import { Body, Controller, Get, Post, Query, UseGuards } from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { Roles } from "/@/logical/adminModule/auth/roles.decorator";
import {
  AddGoodsDto,
  DelGoodsDto,
  EditGoodsDto,
  GetGoodsByTypeDto,
  GetGoodsDto,
} from "../dto/goods.dto";
import { GoodsService } from "../service/goods.service";
import { AuthEnum } from "/@/enum/auth.enum";
import { RolesGuard } from "/@/logical/adminModule/auth/roles.guard";

@ApiTags("goods")
@Controller("goods")
@UseGuards(RolesGuard)
export class GoodsController {
  constructor(private readonly goodsService: GoodsService) {
    //
  }

  @Get("getGoodsList")
  @Roles(AuthEnum.GOODS, AuthEnum.GOODS_VIEW)
  @ApiOperation({ summary: "获取商品列表" })
  async getGoodsList(@Query() query: GetGoodsDto): Promise<any> {
    return this.goodsService.getGoodsList(query);
  }

  @Get("getGoodsListByType")
  @Roles(AuthEnum.GOODS, AuthEnum.GOODS_VIEW, AuthEnum.OPERATE)
  @ApiOperation({ summary: "根据类型获取商品列表" })
  async getGoodsListByType(@Query() query: GetGoodsByTypeDto): Promise<any> {
    return this.goodsService.getGoodsListByType(query);
  }

  @Post("addGoods")
  @Roles(AuthEnum.GOODS)
  @ApiOperation({ summary: "添加商品" })
  async addGoods(@Body() params: AddGoodsDto): Promise<any> {
    return this.goodsService.addGoods(params);
  }

  @Post("editGoods")
  @Roles(AuthEnum.GOODS)
  @ApiOperation({ summary: "编辑商品" })
  async editGoods(@Body() params: EditGoodsDto): Promise<any> {
    return this.goodsService.editGoods(params);
  }

  @Post("delGoods")
  @Roles(AuthEnum.GOODS)
  @ApiOperation({ summary: "删除商品" })
  async delGoods(@Body() params: DelGoodsDto): Promise<any> {
    return this.goodsService.delGoods(params);
  }
}
